//
//  SGMainViewController.swift
//  songguo
//
//  Created by 潘传洲 on 16/6/3.
//  Copyright © 2016年 pcz. All rights reserved.
//

import UIKit

class SGMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        setupView()
        setupAllChildVC()
    }
}
//MARK:- 加载布局界面
extension SGMainViewController{
    
    func setupChildVC(name : String, childViewController : UIViewController, imageName : String, selectedImageName : String) {
        
        
        let nav = UINavigationController(rootViewController: childViewController)
        childViewController.title = name;
        childViewController.tabBarItem.image = UIImage(named: imageName)
        childViewController.tabBarItem.selectedImage = UIImage(named: selectedImageName)
        addChildViewController(nav)
    }
    
    func setupAllChildVC()  {
        
        //子控制器
        let childControllers = [SGHomeTableVC(),SGExploreVC(),SGEventTableVC(),SGMeVC()]
        
        //子控制器的标题
        let controllerNames = ["精选", "探索", "活动", "我"]
        
        // 子控制器的图片
        let imageNames = ["tab_home_24x24_", "tab_explore_24x24_", "tab_event_24x24_", "tab_me_24x24_"]
        
        //子控制器的选中图片
        let selectedImageNames = ["tab_home_active_24x24_", "tab_explore_active_24x24_", "tab_event_active_24x24_", "tab_me_active_24x24_"]
        
        for i in 0..<childControllers.count {
            setupChildVC(controllerNames[i], childViewController: childControllers[i], imageName: imageNames[i], selectedImageName: selectedImageNames[i])
        }
        
    }
    
    
    func setupView() {
        
        
        let item = UITabBarItem.appearanceWhenContainedInInstancesOfClasses([self.classForCoder])
        let attr = [NSForegroundColorAttributeName : globalColor]
        // 设置选中状态的tabBarButton
        item.setTitleTextAttributes(attr, forState: .Selected)
        
        let attrNor = [NSFontAttributeName : UIFont.systemFontOfSize(12)]
        item.setTitleTextAttributes(attrNor, forState: .Normal)
        
        tabBar.backgroundColor = UIColor.whiteColor()
    }
}